import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guide_certification";

export const user_info_api = (showError = true) => {
  return Http.get<any>(`/v3${baseUrl}/user_info`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const edit_config_api = (showError = true) => {
  return Http.get<{
    language: string[];
    credential: { credential: string[]; level: string[] };
    tag: { good: string[]; other: string[] };
    area: { id: number; name: string; city_list: any[] }[];
    scenic: { id: number; name: string; scenic_list: any[] }[];
  }>(`/v3${baseUrl}/edit_config`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const edit_api = (data: any, showError = true) => {
  return Http.post(`/v3${baseUrl}/edit`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
